package com.xhs.service.impl;

import cn.hutool.core.io.FileUtil;
import com.xhs.dto.request.CopyFileRequest;
import com.xhs.message.Result;
import com.xhs.message.ReturnResult;
import com.xhs.service.CopyFileService;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * @desc:
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/3 22:11
 * @version: JDK 1.8
 */
@Service
public class CopyFileServiceImpl implements CopyFileService {
    /**
     * 拷贝文件
     *
     * @param copyFileRequest
     * @return
     */
    @Override
    public ReturnResult<Object> copyFile(CopyFileRequest copyFileRequest) {
//        try {
//            //被复制到此文件中
//            FileOutputStream newFile = new FileOutputStream(new File("D:\\\\file\\\\test.jpeg"));
//            //文件源
//            Resource resource = new ClassPathResource("/test1.jpeg");
//            InputStream inputStream = resource.getInputStream();
//            // 将test1.jpeg复制给D:\\file\\test.jpeg
//            int copy = FileCopyUtils.copy(inputStream, newFile);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        File file = FileUtil.copy(copyFileRequest.getOldFileUrl(), copyFileRequest.getNewFileUrl(), true);
        return ReturnResult.build(Result.COPY_SUCCESS);
    }

}
